<style type="text/css">
<!--
* {margin:0; padding:0;}
.wrap { width:250px; margin:5px;}
.wrap h4 { line-height:30px; border-bottom:1px solid #993300; margin-bottom:5px;}
.wrap label{ display:inline-block; width:80px; line-height:25px;}

.tables { background:#996600;text-align:center; border-collapse:separate;border-spacing:1px;}
.tables td {background:#fff; padding:0 8px;}
.tables th { padding:0 16px; background:#fff;}
-->
</style>
<?php
error_reporting(E_ALL & ~E_NOTICE);
require_once("qqcon.php");
header("Content-Type:text/html; charset=utf-8");

$res1=mysql_query("select * from qqslink");

echo "<table class='tables'>";
echo "<tr><th>id</th><th>qq</th><th>点击数</th><th>状态</th><th>Delete</th><th>Change</th></tr>";
while($row=mysql_fetch_assoc($res1)){
    if($row['state']==1){
		$sta="正常";
	}else{
		$sta="<font color='red'>停用</font>";
	}
	echo "<tr><td>$row[id]</td><td>$row[qq]</td><td>$row[clicks]</td><td>$sta</td><td><a href='qqadmin.php?delid=$row[id]'>删除</a></td><td><a href='qqadmin.php?onoffid=$row[id]&sta=$row[state]'>停用/启用</a></td></tr>";
}
echo "</table>";
mysql_free_result($res1);

//添加QQ
if(!empty($_POST['qq'])){
	$sql="insert into qqslink(qq,clicks,state) values ('$_POST[qq]','$_POST[clicks]','1')";
	$res2=mysql_query($sql) or die(mysql_error());
	if(!$res2){
		echo '<script>alert(\'添加失败！\');location.href=\'qqadmin.php\';</script>';
		}else{
		echo '<script>alert(\'添加成功！\');location.href=\'qqadmin.php\';</script>';
	}
}


//删除QQ
if(!empty($_GET['delid'])){
	$res3=mysql_query("delete from qqslink where id='$_GET[delid]'");
	if(!$res3){
		echo '<script>alert(\'删除失败！\');location.href=\'qqadmin.php\';</script>';
		}else{
		echo '<script>alert(\'成功删除！\');location.href=\'qqadmin.php\';</script>';
	}
}

//停用启用QQ
if(!empty($_GET['onoffid'])){
	if($_GET['sta']==1){
		//停用
		$res4=mysql_query("update qqslink set state='2' where id='$_GET[onoffid]'");
		if(!$res4){
		echo '<script>alert(\'操作失败！\');location.href=\'qqadmin.php\';</script>';
		}else{
		echo '<script>alert(\'操作成功！\');location.href=\'qqadmin.php\';</script>';
		}
	}else{
		//启用
		$res5=mysql_query("update qqslink set state='1' where id='$_GET[onoffid]'");
		if(!$res5){
		echo '<script>alert(\'操作失败！\');location.href=\'qqadmin.php\';</script>';
		}else{
		echo '<script>alert(\'操作成功！\');location.href=\'qqadmin.php\';</script>';
		}
	}
}


?>


<form method="post" action="qqadmin.php">
<div class="wrap">
	<h4>添加QQ</h4>
	<label>QQ号：</label><input type="number" name="qq" /><br />
	<label>点击数：</label><input type="number" name="clicks" value="0" /><br />
	<input type="submit" value="提交" /></div>
</form>

